home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / lazercmd.c < prev    next >
C/C++ Source or Header  |  2000-05-20  |  4KB  |  154 lines

  1. /*************************************************************/
  2. /*                                                           */
  3. /* Lazer Command video handler                               */
  4. /*                                                           */
  5. /*************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "artwork.h"
  9. #include "vidhrdw/generic.h"
  10. #include "vidhrdw/lazercmd.h"
  11.  
  12. extern int marker_x, marker_y;
  13.  
  14. static int video_inverted = 0;
  15.  
  16.  
  17. #define JADE    0x20,0xb0,0x20,OVERLAY_DEFAULT_OPACITY
  18. #define MUSTARD 0xb0,0x80,0x20,OVERLAY_DEFAULT_OPACITY
  19.  
  20. #define    END  {{ -1, -1, -1, -1}, 0,0,0,0}
  21.  
  22. static const struct artwork_element overlay[]=
  23. {
  24.     {{  0*HORZ_CHR, 16*HORZ_CHR-1,  0*VERT_CHR, 1*VERT_CHR-1 }, MUSTARD },
  25.     {{ 16*HORZ_CHR, 32*HORZ_CHR-1,  0*VERT_CHR, 1*VERT_CHR-1 }, JADE    },
  26.     {{  0*HORZ_CHR, 16*HORZ_CHR-1,  1*VERT_CHR,22*VERT_CHR-1 }, JADE    },
  27.     {{ 16*HORZ_CHR, 32*HORZ_CHR-1,  1*VERT_CHR,22*VERT_CHR-1 }, MUSTARD },
  28.     {{  0*HORZ_CHR, 16*HORZ_CHR-1, 22*VERT_CHR,23*VERT_CHR-1 }, MUSTARD },
  29.     {{ 16*HORZ_CHR, 32*HORZ_CHR-1, 22*VERT_CHR,23*VERT_CHR-1 }, JADE    },
  30.     END
  31. };
  32.  
  33. /* scale a markers vertical position */
  34. /* the following table shows how the markers */
  35. /* vertical position worked in hardware  */
  36. /*  marker_y  lines    marker_y  lines   */
  37. /*     0      0 + 1       8      10 + 11 */
  38. /*     1      2 + 3       9      12 + 13 */
  39. /*     2      4 + 5      10      14 + 15 */
  40. /*     3      6 + 7      11      16 + 17 */
  41. /*     4      8 + 9      12      18 + 19 */
  42. static int vert_scale(int data)
  43. {
  44.     return ((data & 0x07)<<1) + ((data & 0xf8)>>3) * VERT_CHR;
  45. }
  46.  
  47. /* mark the character occupied by the marker dirty */
  48. void lazercmd_marker_dirty(int marker)
  49. {
  50.     int x, y;
  51.  
  52.     x = marker_x - 1;             /* normal video lags marker by 1 pixel */
  53.     y = vert_scale(marker_y) - VERT_CHR; /* first line used as scratch pad */
  54.  
  55.     if (x < 0 || x >= HORZ_RES * HORZ_CHR)
  56.         return;
  57.  
  58.     if (y < 0 || y >= (VERT_RES - 1) * VERT_CHR)
  59.         return;
  60.  
  61.     /* mark all occupied character positions dirty */
  62.     dirtybuffer[(y+0)/VERT_CHR * HORZ_RES + (x+0)/HORZ_CHR] = 1;
  63.     dirtybuffer[(y+3)/VERT_CHR * HORZ_RES + (x+0)/HORZ_CHR] = 1;
  64.     dirtybuffer[(y+0)/VERT_CHR * HORZ_RES + (x+3)/HORZ_CHR] = 1;
  65.     dirtybuffer[(y+3)/VERT_CHR * HORZ_RES + (x+3)/HORZ_CHR] = 1;
  66. }
  67.  
  68.  
  69. /* plot a bitmap marker */
  70. /* hardware has 2 marker sizes 2x2 and 4x2 selected by jumper */
  71. /* meadows lanes normaly use 2x2 pixels and lazer command uses either */
  72. static void plot_pattern(struct osd_bitmap *bitmap, int x, int y)
  73. {
  74.     int xbit, ybit, size;
  75.  
  76.     size = 2;
  77.     if (input_port_2_r(0) & 0x40)
  78.     {
  79.         size = 4;
  80.     }
  81.  
  82.     for (ybit = 0; ybit < 2; ybit++)
  83.     {
  84.         if (y+ybit < 0 || y+ybit >= VERT_RES * VERT_CHR)
  85.             return;
  86.  
  87.         for (xbit = 0; xbit < size; xbit++)
  88.         {
  89.             if (x+xbit < 0 || x+xbit >= HORZ_RES * HORZ_CHR)
  90.                 continue;
  91.  
  92.             plot_pixel(bitmap, x+xbit, y+ybit, Machine->pens[2]);
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98. int lazercmd_vh_start(void)
  99. {
  100.     if( generic_vh_start() )
  101.         return 1;
  102.  
  103.     /* is overlay enabled? */
  104.  
  105.     if (input_port_2_r(0) & 0x80)
  106.     {
  107.         overlay_create(overlay, 3, Machine->drv->total_colors-3);
  108.     }
  109.  
  110.     return 0;
  111. }
  112.  
  113.  
  114. void lazercmd_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  115. {
  116.     int i,x,y;
  117.  
  118.     if (video_inverted != (input_port_2_r(0) & 0x20))
  119.     {
  120.         video_inverted = input_port_2_r(0) & 0x20;
  121.         memset(dirtybuffer, 1, videoram_size);
  122.     }
  123.  
  124.     if (palette_recalc() || full_refresh)
  125.         memset(dirtybuffer, 1, videoram_size);
  126.  
  127.     /* The first row of characters are invisible */
  128.     for (i = 0; i < (VERT_RES - 1) * HORZ_RES; i++)
  129.     {
  130.         if (dirtybuffer[i])
  131.         {
  132.             int sx,sy;
  133.  
  134.             dirtybuffer[i] = 0;
  135.  
  136.             sx = i % HORZ_RES;
  137.             sy = i / HORZ_RES;
  138.  
  139.             sx *= HORZ_CHR;
  140.             sy *= VERT_CHR;
  141.  
  142.             drawgfx(bitmap, Machine->gfx[0],
  143.                     videoram[i], video_inverted ? 1 : 0,
  144.                     0,0,
  145.                     sx,sy,
  146.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  147.         }
  148.     }
  149.  
  150.     x = marker_x - 1;             /* normal video lags marker by 1 pixel */
  151.     y = vert_scale(marker_y) - VERT_CHR; /* first line used as scratch pad */
  152.     plot_pattern(bitmap,x,y);
  153. }
  154.